<div class="right-side selection">
    <div class="btn-group">
        <div class="btn-group">
            <a href="<?=base_url().'ranking'?>">
                <button type="button" class="btn btn-default">
                    查看全部
                </button></a>
        </div>
        <div class="btn-group">
            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                正在进行
                <span class="caret"></span>
            </button>
            <ul class="dropdown-menu">
                <?php
                $i = 0;
                foreach($category as $value) {
                    if ($value['deadline'] - now() > 0) {
                        echo '<li><a href="'.base_url().'ranking/search?id='.$value['id'].'">'.$value['category'].'</a></li>';
                        $i++;
                    }
                }
                if ($i == 0)
                    echo '<li><a href="#">暂无</a></li>';
                ?>
            </ul>
        </div>
        <div class="btn-group">
            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                已结束
                <span class="caret"></span>
            </button>
            <ul class="dropdown-menu">
                <?php
                $i = 0;
                foreach($category as $value) {
                    if ($value['deadline'] - now() < 0) {
                        echo '<li><a href="'.base_url().'ranking/search?id='.$value['id'].'">'.$value['category'].'</a></li>';
                        $i++;
                    }
                }
                if ($i == 0)
                    echo '<li><a href="#">暂无</a></li>';
                ?>
            </ul>
        </div>
    </div>
</div>
<h1 id="titlename">排行榜</h1>
<div class="center-block">
    <?php
        foreach($check as $value) {
            echo '<h2 class="text-center">'.$value['category'].'</h2>';
            echo '<table class="table table-hover">';
            echo '<tr><th>排名</th><th>作品名</th><th>创作者</th><th>学院</th><th>得票数</th><tr/>';
            $i = 1;     // counter
            foreach($rank as $val) {
                if ($val['category'] == $value['category']) {
                    echo '<tr>';
                    echo '<td>'.$i.'</td>';
                    echo '<td><a href="'.base_url().'detail?pid='.$val['pid'].'">'.$val['title'].'</a></td>';
                    echo '<td>'.$val['realname'].'</td>';
                    echo '<td>'.$val['name'].'</td>';
                    echo '<td>'.$val['count(pr_rates.ip)'].'</td>';
                    $i++;
                }
                if ($i > 10)
                    break;
            }
            echo '</table>';
        }
    ?>
</div>